﻿using System;
using System.Windows.Media;
using OpenAiClient.Tools;
using Prism.Commands;

namespace OpenAiClient.Models
{
    internal class HistoryDto
    {
        public event Action<HistoryDto> OnCopyQuestion = (_) => { };
        public event Action<HistoryDto> OnCopyAnswer = (_) => { };
        public event Action<HistoryDto> OnDeleteItem = (_) => { };

        public DelegateCommand CopyQuestionCommand { get; }
        public DelegateCommand CopyAnswerCommand { get; }
        public DelegateCommand DeleteItemCommand { get; }

        public int Index { get; set; }
        public string? Id => _model.Id;
        public string? Question => _model.Question;
        public string? Answer => _model.Answer;
        public string? ErrorMessage => _model.ErrorMessage;
        public DateTime CreateTime => _model.CreateTime;
        public bool IsSuccess => _model.IsSuccess == 1;
        public string SuccessState => IsSuccess ? "成功" : "失败";
        public string? Result => IsSuccess ? Answer : ErrorMessage;

        public Brush SuccessStateBrush => IsSuccess
            ? Constants.Brushes.SucceedTextBrush
            : Constants.Brushes.FailedTextBrush;

        private readonly HistoryModel _model;

        public HistoryDto(HistoryModel model)
        {
            _model = model;
            CopyQuestionCommand = new DelegateCommand(() => { OnCopyQuestion.Invoke(this); });
            CopyAnswerCommand = new DelegateCommand(() => { OnCopyAnswer.Invoke(this); });
            DeleteItemCommand = new DelegateCommand(() => { OnDeleteItem.Invoke(this); });
        }
    }
}
